package com.lukk.controller;

import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lukk.pojo.Merchant;
import com.lukk.service.IMerchantService;

/**
 * 
 * MerchantController 上午10:21:44
 * 
 * Copyright zhaocj Inc. All rights reserved.
 * Love ME Like Justin Bieber.
 */
@Controller
@RequestMapping("/merchant")
public class MerchantController {
	private static Logger logger = LogManager.getLogger(MerchantController.class.getName());
	@Resource
	IMerchantService merchantService;

	// 解析视图
	@RequestMapping("/merchantMine")
	public String verifyingWorker(Model model) {
		model.addAttribute("oneMenu", "merchantIndentManage");
		model.addAttribute("twoMenu", "merchantMine");
		return "/cms/merchantIndentManage/merchantMine";
	}

	/**
	 * 
	 * @param offset
	 * @param limit
	 * @param sort
	 * @param order
	 * @param queryStatus
	 *            0:查询未分配的
	 * @return
	 */
	@RequestMapping("/queryByPageAndQueryStatus")
	public @ResponseBody Map<String, Object> queryByPageAndQueryStatus(Integer offset, Integer limit, String sort,
			String order, String merchantName, String merchantPhone, String queryStatus) {
		logger.debug("查询的参数是：{}，{}，{}，{}，{}，{}，{}", offset, limit, sort, order, queryStatus, merchantName,
				merchantPhone);
		return merchantService.selectByPageAndQueryStatus(offset, limit, sort, order, merchantName, merchantPhone,
				queryStatus);
	}

	@RequestMapping("/allocateMerchants")
	public @ResponseBody boolean allocateMerchantForInternalWorker(String merchants, String interID) {
		logger.debug("传入的参数有：{},{}", merchants, interID);
		return merchantService.modifyMerchantForInternalWorker(merchants, interID);
	}

	/**
	 * 
	 * @param merchantID
	 * @return
	 */
	@RequestMapping("/queryByPrimaryKey")
	public @ResponseBody Merchant queryByPrimaryKey(Integer merchantID) {
		logger.debug("要查询的merchantID的ID值：{}", merchantID);
		return merchantService.selectByPrimaryKey(merchantID);
	}

	@RequestMapping("/queryMerchantByInternalWorker")
	public @ResponseBody Map<String, Object> queryWorkersByProvinceCode(Integer offset, Integer limit, String sort,
			String order, String merchantName, String merchantPhone, HttpSession session) {
		logger.debug("想要查询工人的城市的code是：{}，{}，{}，{}，{}，{}", offset, limit, sort, order, merchantName, merchantPhone);
		return merchantService.selectMerchantByInternalWorker(offset, limit, sort, order, merchantName, merchantPhone,
				session);
	}
}
